package com.app.controller;

import com.app.model.ExpertModel;
import com.app.model.OperationRecordsModel;
import com.app.model.UserModel;
import com.app.service.ExpertService;
import com.app.service.OperationRecordsService;
import com.app.service.UserService;
import com.app.util.CommonHelp;
import com.app.util.Result;
import com.app.util.StringTool;
import com.app.util.TokenUtils;
import com.app.vo.ExpertVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletRequest;

/**
 * @Description: 操作记录
 * @Author: N
 * @Date: 2022/10/29 15:26
 */
@RestController
@RequestMapping("/")
public class OperationRecordsController {
    @Autowired
    OperationRecordsService operationRecordsService;
    @Autowired
    UserService userService;

    @GetMapping("/doOperationRecords")
    public Result<Object> doOperationRecords(HttpServletRequest request, OperationRecordsModel model) {
        String token = request.getHeader("token");
        if(StringTool.isNotEmpty(token))
        {
            String mobile = TokenUtils.nothingness(token);
            if (mobile == null) {
                return Result.error(405, "token不存在");
            }
            UserModel user = userService.getUserByMobile(mobile);
            if (user == null) {
                return Result.error(405, "用户不存在");
            }
            model.setUserId(user.getId());
        }
        model.setCrtTime(CommonHelp.getNowTimestamp());
        operationRecordsService.insert(model);
        return Result.success("操作成功");
    }


}
